#include "Person.h"

using namespace std;
using namespace cv;

Person::Person(int i){id = i;}
Person::Person(){id = 0;}
Person::~Person(){}

/*Get values*/
int Person::getId(){return id;}

float Person::getDistance(){return distance;}
float Person::getSpeed(){return speed;}
float Person::getHandHeadRatio(){return handHeadRatio;}
int Person::getPose(){return pose;}
int Person::getCentreX(){return centreX;}
int Person::getCentreY(){return centreY;}
int Person::getMaxX(){return maxX;}
int Person::getMinX(){return minX;}
int Person::getMaxY(){return maxY;}
int Person::getMinY(){return minY;}
string Person::getGesture(){return gesture;}
Point2i Person::getHandPos(){return handPos;}
Point2i Person::getCentrePos(){return centrePos;}

/*Set values*/
void Person::setDistance(float d){distance = d;}
void Person::setSpeed(float s){speed = s;}
void Person::setHandHeadRatio(float r){handHeadRatio = r;}
void Person::setPose(int p){pose = p;}
void Person::setCentre(int x, int y){centreX = x;centreY = y;}
void Person::setMaxX(int x){maxX = x;}
void Person::setMinX(int x){minX = x;}
void Person::setMaxY(int y){maxY = y;}
void Person::setMinY(int y){minY = y;}
void Person::setGesture(string s){gesture = s;};
void Person::setHandPos(int xPos, int yPos){handPos.x = xPos;handPos.y = yPos;}
void Person::setCentrePos(int xPos, int yPos){centrePos.x = xPos;centrePos.y = yPos;}

/*Print person*/
void Person::print(){
    std::cout << "Person centre: " << centreX << " , " << centreY << std::endl;
    std::cout << "Min and max X: " << minX << " , " << maxX << std::endl;
    std::cout << "Min and max Y: " << minY << " , "<< maxY << std::endl;

}


void Person::printXml(TiXmlElement& doc){
    stringstream ss;

    /*Create person node*/
	TiXmlElement *person = new TiXmlElement("Person");
	person->SetAttribute("id", this->getId());
	doc.LinkEndChild(person);

    /*Add distance node*/
	ss << this->getDistance();
    string distString = ss.str();
    TiXmlElement *addDistance = addElement("Distance", distString);

    /*Add pose node*/
    ss.str("");
	ss << this->getPose();
    string poseString = ss.str();
    TiXmlElement *addPose = addElement("Pose", poseString);


    /* Add position node */
    ss.str("");
	ss << this->getCentrePos().x;
    string positionString = ss.str();
    TiXmlElement *addPosition = addElement("Position", positionString);

    /* Add gesture node */
    ss.str("");
	ss << this->getGesture();
    string gestureString = ss.str();
    TiXmlElement *addGesture = addElement("Gesture", gestureString);

    /*Add speed node*/
    ss.str("");
	ss << this->getSpeed();
    string speedString = ss.str();
    TiXmlElement *addSpeed = addElement("Speed", speedString);

    /*Link nodes*/
	person->LinkEndChild(addDistance);
	person->LinkEndChild(addPose);
	person->LinkEndChild(addPosition);
	person->LinkEndChild(addGesture);
	person->LinkEndChild(addSpeed);

}



TiXmlElement* Person::addElement(const char* name, std::string text){
    const char *textPtr = text.c_str();
	TiXmlElement *element = new TiXmlElement(name);
	TiXmlText *pText = new TiXmlText(textPtr);
	element->LinkEndChild(pText);

	return element;

}
